#include<bits/stdc++.h>
using namespace std;
const int N=1000009;
int T;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        int n,m,l,V,d[N],v[N],a[N],p[N],pd[N],ans1,ans2,maxd;
        cin>>n>>m;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int i=1;i<=m;i++){
            cin>>p[i];
            maxd=max(maxd,d[i]);
        }
        for(int i=1;i<=n;i++){
            if(v[i]>V){
                ans1++;
            }
        }
        for(int i=1;i<=m;i++){
            if(p[i]<maxd){
                ans2++;
            }
        }
        cout<<ans1<<" "<<ans2<<endl;
    }
    return 0;
}
